package com.aida.evil.eda.Answer;

import android.app.Activity;
import android.content.DialogInterface;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.aida.evil.aida.R;
import com.aida.evil.eda.Data.NetworkData;
import com.aida.evil.eda.Data.UserData;
import com.aida.evil.eda.Login.Encryp_AES;
import com.aida.evil.eda.Volley.VolleyHandler;
import com.aida.evil.eda.Volley.VolleyHttpRequest;
import com.aida.evil.eda.Window.CustomDialog;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/********************************************
 * 工程名：Aida
 * 包名：com.aida.evil.eda.Answer
 * 时间：16-5-6 上午9:29
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：
 ********************************************/
public class Answer
{
    /*流量提交*/
    private static final String SUBMITURL = "http://" + NetworkData.ServiceIP + "/AnswerResult";


    public static SparseArray<Boolean> answerChoose;
    public static ArrayList<Integer> flowList;
    public static SparseArray<Integer> selectList;

    public static abstract class showDialog
    {
        private Activity activity;
        private TextView textView;
        private ProgressBar progressBar;
        private CustomDialog.Builder builder;

        public abstract void clear();

        public showDialog(Activity activity)
        {
            this.activity = activity;
        }

        public void show()
        {
            builder = new CustomDialog.Builder(activity);
            builder.setTitle("警告！");
            // builder.setMessage("您如果现在退出，将不会得到任何积分，并且将不能再次回答此题！\n是否继续？");
            View view = View.inflate(activity, R.layout.dialog_update_progress, null);
            textView = (TextView) view.findViewById(R.id.update_textView);
            progressBar = (ProgressBar) view.findViewById(R.id.update_progressBar);
            progressBar.setVisibility(View.GONE);
            textView.setText("您如果现在退出，将不会得到任何积分，并且将不能再次回答此题！\n是否继续？");
            builder.setContentView(view);
            builder.setPositiveButton("退出", new DialogInterface.OnClickListener()
            {
                @Override
                public void onClick(DialogInterface dialog, int which)
                {
                    progressBar.setVisibility(View.VISIBLE);
                    textView.setText("正在退出，请稍后！");
                    toNetWork();
                }
            });
            builder.setNegativeButton("取消", new DialogInterface.OnClickListener()
            {
                @Override
                public void onClick(DialogInterface dialog, int which)
                {
                    builder.dismiss();
                }
            });
            builder.show();
        }

        public void finish()
        {
            AnswerActivity.viewPager.removeAllViews();
            activity.finish();
            Answer.answerChoose = null;
            Answer.selectList = null;
            Answer.flowList = null;
            clear();
        }

        public void toNetWork()
        {
            VolleyHandler<String> stringVolleyHandler = new VolleyHandler<String>()
            {
                @Override
                public void reqSuccess(String response)
                {
                    if (builder != null)
                        builder.dismiss();
                    finish();
                    progressBar.setVisibility(View.GONE);

                }

                @Override
                public void reqError(String error)
                {
                    progressBar.setVisibility(View.GONE);
                }
            };
            Map<String, String> map = new HashMap<>();
            map.put("userPhoneNum", UserData.DATA_PHONENUM);
            map.put("itemID", AnswerActivity.itemID + "");
            map.put("over", 1 + "");/*0为全部完成,1为未全部完成*/
            map.put("flowSum", Encryp_AES.getAESCode(0 + ""));
            map.put("yesNum", 0 + "");
            map.put("size", 0 + "");

            VolleyHttpRequest.String_request(SUBMITURL, map, stringVolleyHandler);

            Log.i("userPhoneNum", UserData.DATA_PHONENUM);
            Log.i("itemID", AnswerActivity.itemID + "");
            Log.i("over", 1 + "");
            Log.i("flowSum", Encryp_AES.getAESCode(0 + ""));
            Log.i("yesNum", 0 + "");
            Log.i("size", 0 + "");

        }
    }

}
